import SearchTop from "../../components/newSearchTop.vue";
import $store from "../../components/vuex.js"  // 引入新建的store 变量
import bindPhone  from "../../components/bindPhone.vue"
import Footer from "../../components/footer.vue"
import slider from "../../components/sliders.vue";
import axios from 'axios';
import SearchTitle from "../../components/newSearchTitle.vue";
import newPage from "../../components/newPage.vue"
export default {
	components:{
		SearchTop:SearchTop,
		bindPhone:bindPhone,
		Footer:Footer,
		slider:slider,
		SearchTitle:SearchTitle,
		newPage:newPage,
	},
	data(){
		return{
			banners:[],
			flag:true,
			newGiftList:[],
			hotGiftList:[],
			hotGiftListC:[],
			allGiftList:[],
		}

	},
	mounted(){
		this.getBanner()
		this.getNewGift()
		this.getHotGift()

	},
	filters:{// 自定义时间过滤器
		time:function(date){

			var date = new Date(date);//如果date为10位不需要乘1000
		    var Y = date.getFullYear() + '-';
		    var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
		    var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
		    return Y+M+D;

		},
		giftType:function(value){ // 过滤礼包类型
			if(value=='0'){
				return "免费礼包";

			}else if(value=='1'){
				return "积分礼包";

			}else if(value='=2'){

				return "付费礼包";

			}else{
				return "礼包";
			}
		},
	},
	methods:{
		getBanner(){// 获取轮播图
			let url = "/gift/api/giftbag/querySlideShow.do"
			let that=this;
			axios.get(url).then(function(res){
				if(res.data.code==0 || JSON.stringify(res.data.columnList)!='[]'){
					console.log(res.data.columnList)
					that.banners = res.data.columnList

					that.banners.map(function(item,index){
						item.poster=item.image;
					})
				}else{
					$toast.center("请求错误")
				}

			},function(err){

			})
		},
		getNewGift(){// 获取新游礼包
			let url = "/gift/api/giftbag/newGame.do"
			let that=this;
			axios.get(url).then(function(res){
				if(res.data.code==0 || JSON.stringify(res.data.columnList)!='[]'){
					console.log(res.data.columnList)
					that.newGiftList = res.data.columnList
				}else{
					$toast.center("请求错误")
				}

			},function(err){


			})


		},
		getHotGift(){// 获取热门礼包
			let url = "/gift/api/giftbag/queryHotGiftBag.do"
			let that=this;
			axios.get(url).then(function(res){
				if(res.data.code==0 || JSON.stringify(res.data.giftBags)!='[]'){
					that.hotGiftList = res.data.giftBags;

					that.changeArr(that.hotGiftList)
					
				}else{
					$toast.center("请求错误")
				}

			},function(err){

			})
		},
		changeArr(arr){// 换一换
			this.hotGiftListC=[];
//hotGiftListC
			
			for(var i=0;i<2;i++){
				let num = Math.ceil(Math.random(0,1)*arr.length)
				this.hotGiftListC.push(this.hotGiftList[num])

			}
			
		},
		getAllGift(data){// 获取热门礼包
			console.log(data)

			this.allGiftList=data

			if(JSON.stringify(data)=='[]'){
				this.flag=false;
				this.allGiftList=data
				
			}else{

				this.allGiftList=data
				this.flag=true;

			}

		},
		goGiftDeta(giftId){


			this.$router.push({path:"../newGiftDetails",query:{giftId:giftId}})

		}



	}
	
}